#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    stack<int> stk;
    for(int i = 0; i < n; i++){
        string op; cin >> op;
        if(op == "push"){
            int x; cin >> x;
            stk.push(x);

        }else if(op == "pop"){
            if(stk.empty()){
                cout << "error\n";
                continue;
            }else{
                cout << stk.top() << '\n';
                stk.pop();
            }
        }else if(op == "top"){
            if(stk.empty()){
                cout << "error\n";
                continue;
            }else{
                cout << stk.top() << '\n';
            }
            
        }
    }
    return 0;
}